var lpdhInterface = function() {
	var ywy  = manager.findParamFromUrl('ywy') ? manager.findParamFromUrl('ywy'):'000000';//业务域（先写死）
	var currPage = 1;
	// 获取全部礼品数据
	function getlpxqDate(fn) {	
		//判断当前tab选项
		var currTabUrl = $('.lpdh-tab>li.active').attr('data-url');
		var data={
				"currPage":currPage,
				"pageSize":8,
				"ywy":ywy
		};
		$.ajax({
			type : "post",
			data:JSON.stringify(data),
			dateType : "json",
			contentType : 'application/json;charset=UTF-8',
			url : Constants.csUrlPath + currTabUrl,
			success : function(data) {
				fn.call("", data);
			}
		});
	}
	//蒙层显示
	$('.lpdhList').delegate('.pic','mouseover',function(){
		$(this).children('.mask').css('visibility','visible');
		$(this).children('.mask').stop().animate({width:"264px"},'normal')
		}).delegate('.pic','mouseout',function(){
			$(this).children('.mask').stop().animate({width:"0"},'normal')
			$(this).children('.mask').css('visibility','hidden');
	})
	//tab切换
	$(".lpdh-tab>li").on('click',function(e){
		$('.more').addClass('none');
		currPage = 1
		$('.lpdh-tab>li').removeClass('active');
		$(this).addClass('active');
		var str='<div id="loading" style="font-size: 14px;font-weight: bold;color: #f60;height: 40px;width: 250px;line-height: 40px;text-align: center;margin: 0 auto;"><img alt="" src="../../img/loading.gif"></div>';
		$('#qblp-container').html(str);
		var ractive = new Ractive({
			el : '#qblp-container',
			template : "#qblp-template",
			data : {
				"islogin" : false
			},
			oncomplete : function() {
				// 设置全部礼品数据
				getlpxqDate(function(data) {
					    $('#loading').addClass('none');
					    $('.noData').removeClass('none');
						ractive.set("qblp", data);
						ractive.set('imgUrl',Constants.imgUrl);
						if(data&&data.total<9){
							$('.more').addClass('none');
						}
						else{
							$('.more').removeClass('none');
						}		
				});
			}
		});
	})
	//点击加载更多显示更多数据
	$('.more>span').on('click',function(){
		currPage++;
		var ractive = new Ractive({
			el : '#more-container',
			template : "#qblp-template",
			data : {
				"islogin" : false
			},
			oncomplete : function() {
				// 设置全部礼品数据
				getlpxqDate(function(data) {
					ractive.set("qblp", data);
					ractive.set('imgUrl',Constants.imgUrl);
					var currNum  = data.currPage*8,
					    totalNum = data.total;
					if(totalNum - currNum<9){//判断是否是最后一页
						$('.more').addClass('none');
					}
					else{
						$('.more').removeClass('none');
					}
					$('#qblp-container').append($('#more-container').html());
				});
			}
		});
	})
	//点击描述其他地方，跳详情页
	$(document).delegate('.desc','click',function(e){
		if($(e.target).closest("a").length>0){
			return;
		}
		var targetSrc = $(this).attr('data-src');
		window.open(targetSrc);
	})
	//加载数据
	function load() {
		var str='<div id="loading" style="font-size: 14px;font-weight: bold;color: #f60;height: 40px;width: 250px;line-height: 40px;text-align: center;margin: 0 auto;"><img alt="" src="../../img/loading.gif"></div>';
		$('#qblp-container').html(str);
		var ractive = new Ractive({
			el : '#qblp-container',
			template : "#qblp-template",
			data : {
				"islogin" : false
			},
			oncomplete : function() {
				// 设置全部礼品数据
				getlpxqDate(function(data) {
					    $('#loading').addClass('none');
					    $('.noData').removeClass('none');
						ractive.set("qblp", data);
						ractive.set('imgUrl',Constants.imgUrl);
						if(data&&data.total<9){
							$('.more').addClass('none');
						}
						else{
							$('.more').removeClass('none');
						}
				});
			}
		});
	}
	return {
		init : function() {
			load();
		}

	}
}();
$(document).ready(lpdhInterface.init);